package com.zlb.demo.exception;

import com.zlb.demo.domain.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Description 全局异常处理
 * @Author zlb
 * @Since 2024-03-120 11:46:59
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = ServiceException.class)
    public R<?> errorHandler(ServiceException e) {
        return R.fail(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public R<?> errorHandler(Exception e) {
        e.printStackTrace();
        return R.fail("500", e.getMessage());
    }

}
